package com.kacheap.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.activemq.ScheduledMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kacheap.config.jms.JmsConsumer;

@RestController
public class SendController {
	private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	
	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;
	
	
	

	@GetMapping("/mq/send")
	public String send() {
		// String message = format.format(new Date()) + " ===> 大家好, 我是一则实时消息.......";
		// jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(AlarmConsumer.QUEUE_NAME), message);
		
		
		
		String message = format.format(new Date()) + " ===> 大家好, 我是一则延迟消息.......";
		Map<String, Object> headers = new HashMap<String, Object>(2);
        headers.put(ScheduledMessage.AMQ_SCHEDULED_DELAY, 1000 * 1);
		jmsMessagingTemplate.convertAndSend(JmsConsumer.QUEUE_NAME, message, headers);

		return "Successful";
	}

}
